<html>
<head>
<title>TurKit JavaScript API</title>
<style>

img {
	border-style: none;
}

body {
    font-family:"Trebuchet MS",Arial,Sans-Serif;
}

.func {
    margin-top : 50px;
    border-top : 1px solid #e0e0e0;
	font-weight : bold;
}

.doc {
    margin-top : 25px;
	padding-left : 100px;
}

.param {
	font-family:"Courier New", Courier, Sans-Serif;
	font-weight : normal;
}

.prefix {
	color: #a0a0a0;
	font-weight : normal;
}

.main {
    width:900px;
    margin-left: auto ;
    margin-right: auto ;
}

.index {
    border-top : 1px solid #e0e0e0;
}

.index-list {
    float: left;
    margin-right: 50px;
}

.indent {
	padding-left: 25px;
}

.clear {
    clear: both;
}

</style>
</head>
<body>

<div class="main">

<div style="float:left"><a href="/"><img src="/logos/logo-140.png"></a></div>
<div style="float:right;vertical-align:bottom">JavaScript API</div>
<div style="clear:both"></div>
<div class="index">

<div class="index-list"><div class="index-func"><a href="#once">once</a></div>
<div class="index-func"><a href="#fork">fork</a></div>
<div class="index-func"><a href="#join">join</a></div>
<div class="index-func"><a href="#crash">crash</a></div>
<div class="index-func"><a href="#stop">stop</a></div>
<div class="index-func"><a href="#resetDatabase">resetDatabase</a></div>
</div><div class="index-list"><div class="index-func"><a href="#mturk">mturk</a></div>
<div class="index-func indent"><a href="#mturk.createHIT">createHIT</a></div>
<div class="index-func indent"><a href="#mturk.extendHIT">extendHIT</a></div>
<div class="index-func indent"><a href="#mturk.deleteHIT">deleteHIT</a></div>
<div class="index-func indent"><a href="#mturk.deleteHITs">deleteHITs</a></div>
<div class="index-func indent"><a href="#mturk.grantBonus">grantBonus</a></div>
<div class="index-func indent"><a href="#mturk.approveAssignment">approveAssignment</a></div>
<div class="index-func indent"><a href="#mturk.approveAssignments">approveAssignments</a></div>
<div class="index-func indent"><a href="#mturk.rejectAssignment">rejectAssignment</a></div>
<div class="index-func indent"><a href="#mturk.rejectAssignments">rejectAssignments</a></div>
<div class="index-func indent"><a href="#mturk.waitForHIT">waitForHIT</a></div>
<div class="index-func indent"><a href="#mturk.createHITAndWait">createHITAndWait</a></div>
<div class="index-func indent"><a href="#mturk.prompt">prompt</a></div>
<div class="index-func indent"><a href="#mturk.vote">vote</a></div>
<div class="index-func indent"><a href="#mturk.survey">survey</a></div>
<div class="index-func"><a href="#mturkBase">mturkBase</a></div>
<div class="index-func indent"><a href="#mturkBase.getAccountBalance">getAccountBalance</a></div>
<div class="index-func indent"><a href="#mturkBase.createHIT">createHIT</a></div>
<div class="index-func indent"><a href="#mturkBase.getReviewableHITs">getReviewableHITs</a></div>
<div class="index-func indent"><a href="#mturkBase.getHIT">getHIT</a></div>
<div class="index-func indent"><a href="#mturkBase.extendHIT">extendHIT</a></div>
<div class="index-func indent"><a href="#mturkBase.deleteHIT">deleteHIT</a></div>
<div class="index-func indent"><a href="#mturkBase.grantBonus">grantBonus</a></div>
<div class="index-func indent"><a href="#mturkBase.approveAssignment">approveAssignment</a></div>
<div class="index-func indent"><a href="#mturkBase.rejectAssignment">rejectAssignment</a></div>
<div class="index-func indent"><a href="#mturkBase.getHITs">getHITs</a></div>
</div><div class="index-list"><div class="index-func"><a href="#webpage">webpage</a></div>
<div class="index-func indent"><a href="#webpage.create">create</a></div>
<div class="index-func indent"><a href="#webpage.remove">remove</a></div>
<div class="index-func indent"><a href="#webpage.setData">setData</a></div>
<div class="index-func indent"><a href="#webpage.waitForData">waitForData</a></div>
<div class="index-func indent"><a href="#webpage.createHITTemplate">createHITTemplate</a></div>
<div class="index-func"><a href="#webpageBase">webpageBase</a></div>
<div class="index-func indent"><a href="#webpageBase.create">create</a></div>
<div class="index-func indent"><a href="#webpageBase.remove">remove</a></div>
<div class="index-func indent"><a href="#webpageBase.setData">setData</a></div>
<div class="index-func indent"><a href="#webpageBase.getData">getData</a></div>
</div><div class="index-list"><div class="index-func"><a href="#print">print</a></div>
<div class="index-func"><a href="#verbosePrint">verbosePrint</a></div>
<div class="index-func"><a href="#mTurkRestRequest">mTurkRestRequest</a></div>
<div class="index-func"><a href="#sleep">sleep</a></div>
<div class="index-func"><a href="#md5">md5</a></div>
<div class="index-func"><a href="#json">json</a></div>
<div class="index-func"><a href="#read">read</a></div>
<div class="index-func"><a href="#slurp">slurp</a></div>
<div class="index-func"><a href="#write">write</a></div>
<div class="index-func"><a href="#registerMTurkNotification">registerMTurkNotification</a></div>
<div class="index-func"><a href="#random">random</a></div>
<div class="index-func"><a href="#setSeed">setSeed</a></div>
<div class="index-func"><a href="#swap">swap</a></div>
<div class="index-func"><a href="#shuffle">shuffle</a></div>
<div class="index-func"><a href="#randomIndex">randomIndex</a></div>
<div class="index-func"><a href="#time">time</a></div>
<div class="index-func"><a href="#group">group</a></div>
<div class="index-func"><a href="#safeJson">safeJson</a></div>
<div class="index-func"><a href="#ensure">ensure</a></div>
<div class="index-func"><a href="#values">values</a></div>
<div class="index-func"><a href="#keys">keys</a></div>
<div class="index-func"><a href="#filter">filter</a></div>
<div class="index-func"><a href="#foreach">foreach</a></div>
<div class="index-func"><a href="#map">map</a></div>
<div class="index-func"><a href="#mapToSelf">mapToSelf</a></div>
<div class="index-func"><a href="#fold">fold</a></div>
<div class="index-func"><a href="#trim">trim</a></div>
<div class="index-func"><a href="#last">last</a></div>
<div class="index-func"><a href="#merge">merge</a></div>
<div class="index-func"><a href="#maxHelper">maxHelper</a></div>
<div class="index-func"><a href="#max">max</a></div>
<div class="index-func"><a href="#findMax">findMax</a></div>
<div class="index-func"><a href="#escapeXml">escapeXml</a></div>
<div class="index-func"><a href="#unescapeXml">unescapeXml</a></div>
<div class="index-func"><a href="#Set">Set</a></div>
<div class="index-func indent"><a href="#Set.prototype.clone">clone</a></div>
<div class="index-func indent"><a href="#Set.prototype.remove">remove</a></div>
<div class="index-func indent"><a href="#Set.prototype.add">add</a></div>
<div class="index-func indent"><a href="#Set.prototype.intersect">intersect</a></div>
<div class="index-func"><a href="#Bag">Bag</a></div>
<div class="index-func indent"><a href="#Bag.prototype.clone">clone</a></div>
<div class="index-func indent"><a href="#Bag.prototype.add">add</a></div>
<div class="index-func indent"><a href="#Bag.prototype.get">get</a></div>
<div class="index-func"><a href="#jsonPath">jsonPath</a></div>
<div class="index-func"><a href="#stats">stats</a></div>
<div class="index-func indent"><a href="#stats.sum">sum</a></div>
<div class="index-func indent"><a href="#stats.mean">mean</a></div>
<div class="index-func indent"><a href="#stats.variance">variance</a></div>
<div class="index-func indent"><a href="#stats.sd">sd</a></div>
<div class="index-func indent"><a href="#stats.all">all</a></div>
<div class="index-func"><a href="#highlightDiff">highlightDiff</a></div>
</div>

<div class="clear"></div>
</div>

<a name="once"><div class="func">once(<span class="param">func</span>,<span class="param"> name</span>)</div></a>
<div class="doc">
Calls the function func only once;
subsequent runs of the program will not call func
if it returns successfully this time.
If func crashes, then it will be called again when the program is rerun.

The name parameter is used for error checking.
Subsequent runs of the program will make sure that name is the same.
</div>
<a name="fork"><div class="func">fork(<span class="param">func</span>,<span class="param"> name</span>)</div></a>
<div class="doc">
Executes func in a pseudo-thread;
if func crashes with a call to crash,
the program will keep running after this call to fork.

Returns true iff func finishes successfully.

</div>
<a name="join"><div class="func">join()</div></a>
<div class="doc">
Makes sure all the forks have finished, otherwise we crash.

</div>
<a name="crash"><div class="func">crash(<span class="param">msg</span>)</div></a>
<div class="doc">
Throws a "crash" exception.
This is the preferred way of ending execution
when waiting on external data,
like HITs on Mechanical Turk.

Note that the "crash" exception is caught by fork.

Prints out the given <code>msg</code> too.
</div>
<a name="stop"><div class="func">stop(<span class="param">msg</span>)</div></a>
<div class="doc">
Throws a "crash" exception.
This is a pseudonym for crash.

Prints out the given <code>msg</code> too.
</div>
<a name="resetDatabase"><div class="func">resetDatabase()</div></a>
<div class="doc">
Resets the database.
</div>
<a name="mturk"><div class="func">mturk</div></a>
<div class="doc">
This module contains wrappers around mturkBase functions using once.
You probably want this, so that your HITs are only created once,
even though your script will probably crash and rerun many times.

</div>
<a name="mturk.createHIT"><div class="func"><span class="prefix">mturk.</span>createHIT(<span class="param">params</span>)</div></a>
<div class="doc">
Calls <a href="#mturkBase.createHIT">mturkBase.createHIT</a> inside of <a href="#once">once</a>.
</div>
<a name="mturk.extendHIT"><div class="func"><span class="prefix">mturk.</span>extendHIT(<span class="param">hit</span>,<span class="param"> moreAssignments</span>,<span class="param"> moreSeconds</span>)</div></a>
<div class="doc">
Calls <a href="#mturkBase.extendHIT">mturkBase.extendHIT</a> inside of <a href="#once">once</a>.
</div>
<a name="mturk.deleteHIT"><div class="func"><span class="prefix">mturk.</span>deleteHIT(<span class="param">hit</span>)</div></a>
<div class="doc">
Calls <a href="#mturkBase.deleteHIT">mturkBase.deleteHIT</a> inside of <a href="#once">once</a>.
</div>
<a name="mturk.deleteHITs"><div class="func"><span class="prefix">mturk.</span>deleteHITs(<span class="param">hits</span>)</div></a>
<div class="doc">
Calls <a href="#mturk.deleteHIT">mturk.deleteHIT</a> for each HIT in the given hits array.
</div>
<a name="mturk.grantBonus"><div class="func"><span class="prefix">mturk.</span>grantBonus(<span class="param">assignment</span>,<span class="param"> amount</span>,<span class="param"> reason</span>)</div></a>
<div class="doc">
Calls <a href="#mturkBase.grantBonus">mturkBase.grantBonus</a> inside of <a href="#once">once</a>.
</div>
<a name="mturk.approveAssignment"><div class="func"><span class="prefix">mturk.</span>approveAssignment(<span class="param">assignment</span>,<span class="param"> reason</span>)</div></a>
<div class="doc">
Calls <a href="#mturkBase.approveAssignment">mturkBase.approveAssignment</a> inside of <a href="#once">once</a>.
</div>
<a name="mturk.approveAssignments"><div class="func"><span class="prefix">mturk.</span>approveAssignments(<span class="param">assignments</span>,<span class="param"> reason</span>)</div></a>
<div class="doc">
Calls <a href="#mturk.approveAssignment">mturk.approveAssignment</a> for each assignment in the given
assignments array.
</div>
<a name="mturk.rejectAssignment"><div class="func"><span class="prefix">mturk.</span>rejectAssignment(<span class="param">assignment</span>,<span class="param"> reason</span>)</div></a>
<div class="doc">
Calls <a href="#mturkBase.rejectAssignment">mturkBase.rejectAssignment</a> inside of <a href="#once">once</a>.
</div>
<a name="mturk.rejectAssignments"><div class="func"><span class="prefix">mturk.</span>rejectAssignments(<span class="param">assignments</span>,<span class="param"> reason</span>)</div></a>
<div class="doc">
Calls <a href="#mturk.rejectAssignment">mturk.rejectAssignment</a> for each assignment in the given
assignments array.
</div>
<a name="mturk.waitForHIT"><div class="func"><span class="prefix">mturk.</span>waitForHIT(<span class="param">hit</span>)</div></a>
<div class="doc">
Returns information about the hit if it is done (see <a href="#mturkBase.getHIT">mturkBase.getHIT</a>),
otherwise it crashes.
</div>
<a name="mturk.createHITAndWait"><div class="func"><span class="prefix">mturk.</span>createHITAndWait(<span class="param">params</span>)</div></a>
<div class="doc">
Calls <a href="#mturk.createHIT">mturk.createHIT</a> and then <a href="#mturk.waitForHIT">mturk.waitForHIT</a>,
and returns the results of the completed HIT.
</div>
<a name="mturk.prompt"><div class="func"><span class="prefix">mturk.</span>prompt(<span class="param">message</span>,<span class="param"> params</span>)</div></a>
<div class="doc">
Creates a HIT with the given prompt,
waits for someone to answer it,
and returns the result.
</div>
<a name="mturk.vote"><div class="func"><span class="prefix">mturk.</span>vote(<span class="param">message</span>,<span class="param"> options</span>,<span class="param"> votesNeeded</span>,<span class="param"> params</span>)</div></a>
<div class="doc">
Creates a voting HIT with the given prompt,
waits for people to answer it,
and returns the result.

You may pass in a hitId as the message,
along with a function for <code>options</code>.
The function should accept an assignment object, and return a string
representing the choice selected in that assignment, e.g.,
<pre>
function (assignment) {
return assignment.answer.response
}
</pre>
</div>
<a name="mturk.survey"><div class="func"><span class="prefix">mturk.</span>survey(<span class="param">message</span>,<span class="param"> options</span>,<span class="param"> count</span>,<span class="param"> params</span>)</div></a>
<div class="doc">
Creates a survey HIT with the given prompt,
waits for people to answer it,
and returns the result.
The results is a map of each option to the number of people who chose that option.
</div>
<a name="mturkBase"><div class="func">mturkBase</div></a>
<div class="doc">
This module contains helper functions for making REST requests to Mechanical Turk.

Note that it uses the AWS access keys supplied in props,
as well as the mode (either "real" or "sandbox").
</div>
<a name="mturkBase.getAccountBalance"><div class="func"><span class="prefix">mturkBase.</span>getAccountBalance()</div></a>
<div class="doc">
Returns the number of dollars in the user's MTurk account.
</div>
<a name="mturkBase.createHIT"><div class="func"><span class="prefix">mturkBase.</span>createHIT(<span class="param">params</span>)</div></a>
<div class="doc">
Creates a HIT. params is an object with the following properties:
<ul>
<li><b>title</b>: displayed in the list of HITs on MTurk.</li>
<li><b>description</b>: <b>desc</b> is also accepted.
A slightly longer description of the HIT,
also shown in the list of HITs on MTurk</li>
<li><b>question</b>: a string of XML specifying what will be shown. <a
href="http://docs.amazonwebservices.com/AWSMechanicalTurkRequester/2008-08-02/index.html?ApiReference_QuestionFormDataStructureArticle.html">See documentation here</a>.
Instead of question, you may use the following special parameters:
<ul>
<li><b>url</b>: creates an external question pointing to this URL</li>
<li><b>height</b>: (optional) height of the iFrame embedded in MTurk, in pixels (default is 600).</li>
</ul>
</li>
<li><b>reward</b>: how many dollars you want to pay per assignment for this HIT.
</ul>
The following properties are optional:
<ul>
<li><b>keywords</b>: keywords to help people search for your HIT.</li>
<li><b>assignmentDurationInSeconds</b>: default is 1 hour's worth of seconds.</li>
<li><b>autoApprovalDelayInSeconds</b>: default is 1 month's worth of seconds.</li>
<li><b>lifetimeInSeconds</b>: default is 1 week's worth of seconds.</li>
<li><b>maxAssignments</b>: <b>assignments</b> is also accepted. default is 1.</li>
<li><b>requesterAnnotation</b>: default is no annotation.</li>
<li><b>qualificationRequirements</b>: default is no requirements.</li>
<li><b>minApproval</b>: minimum approval percentage.
The appropriate requirement will be added if you supply a percentage here.</li>
</ul>
</div>
<a name="mturkBase.getReviewableHITs"><div class="func"><span class="prefix">mturkBase.</span>getReviewableHITs(<span class="param">maxPages</span>)</div></a>
<div class="doc">
Returns a list of HIT Ids of HITs that are ready to be reviewed.
You may optionally specify <code>maxPages</code>,
to limit the number of pages of results returned.
Each page will have up to 100 reviewable HIT Ids.
If <code>maxPages</code> is specified,
then the return value will have a property called <code>totalNumResults</code>,
which indicates how many HITs are reviewable.
</div>
<a name="mturkBase.getHIT"><div class="func"><span class="prefix">mturkBase.</span>getHIT(<span class="param">hit</span>,<span class="param"> getAssignments</span>)</div></a>
<div class="doc">
Returns an object representing all of the information MTurk has on the given
HIT, including the assignments, and the associated answer data. The returned
object will have a value called done set to true iff all the pending
assignments for this HIT have been completed (unless getAssignments is false).

getAssignments defaults to true.

Note that the answer data structure associated with each assignment is
simplified. It is recommended that you print out the result of this function
using json, in order to know what it looks like for your specific situation.
</div>
<a name="mturkBase.extendHIT"><div class="func"><span class="prefix">mturkBase.</span>extendHIT(<span class="param">hit</span>,<span class="param"> moreAssignments</span>,<span class="param"> moreSeconds</span>)</div></a>
<div class="doc">
Extends the hit by the given number of assignments (moreAssignments),
and the given number of seconds (moreSeconds).
</div>
<a name="mturkBase.deleteHIT"><div class="func"><span class="prefix">mturkBase.</span>deleteHIT(<span class="param">hit</span>)</div></a>
<div class="doc">
Deletes the given hit.
If there are any completed assignments that have not been approved or rejected,
then they are approved.
</div>
<a name="mturkBase.grantBonus"><div class="func"><span class="prefix">mturkBase.</span>grantBonus(<span class="param">assignment</span>,<span class="param"> amount</span>,<span class="param"> reason</span>)</div></a>
<div class="doc">
Grants a bonus of the given amount to the given
assignment for the stated reason.
</div>
<a name="mturkBase.approveAssignment"><div class="func"><span class="prefix">mturkBase.</span>approveAssignment(<span class="param">assignment</span>,<span class="param"> reason</span>)</div></a>
<div class="doc">
Approves the given assignment, and provides an optional reason.
</div>
<a name="mturkBase.rejectAssignment"><div class="func"><span class="prefix">mturkBase.</span>rejectAssignment(<span class="param">assignment</span>,<span class="param"> reason</span>)</div></a>
<div class="doc">
Rejects the given assignment, and provides an optional reason.
</div>
<a name="mturkBase.getHITs"><div class="func"><span class="prefix">mturkBase.</span>getHITs(<span class="param">maxPages</span>)</div></a>
<div class="doc">
Returns an array of HIT data for all the HITs you currently have on MTurk.
</div>
<a name="webpage"><div class="func">webpage</div></a>
<div class="doc">
This module contains wrappers around webpageBase functions using once.
You probably want this, so that your webpages are only created once,
even though your script will probably crash and rerun many times.
</div>
<a name="webpage.create"><div class="func"><span class="prefix">webpage.</span>create(<span class="param">contents</span>,<span class="param"> blockWorkers</span>)</div></a>
<div class="doc">
Wraps <a href="#webpageBase.create">webpageBase.create</a> in a call to <a href="#once">once</a>.

You can block one or more turkers from doing this HIT by passing them as a string or array to blockWorkers.
</div>
<a name="webpage.remove"><div class="func"><span class="prefix">webpage.</span>remove(<span class="param">url</span>)</div></a>
<div class="doc">
Wraps <a href="#webpageBase.remove">webpageBase.remove</a> in a call to <a href="#once">once</a>.
</div>
<a name="webpage.setData"><div class="func"><span class="prefix">webpage.</span>setData(<span class="param">url</span>,<span class="param"> data</span>)</div></a>
<div class="doc">
Wraps <a href="#webpageBase.setData">webpageBase.setData</a> in a call to <a href="#once">once</a>.
</div>
<a name="webpage.waitForData"><div class="func"><span class="prefix">webpage.</span>waitForData(<span class="param">url</span>)</div></a>
<div class="doc">
If there is data available from the client, this data is returned and remembered
in a call to <a href="#once">once</a>.
If there is no data available, this method calls <a href="#crash">crash</a>.
</div>
<a name="webpage.createHITTemplate"><div class="func"><span class="prefix">webpage.</span>createHITTemplate(<span class="param">html</span>,<span class="param"> blockWorkers</span>)</div></a>
<div class="doc">
Returns a webpage that can be used as a HIT.
The html passed to this function will be pasted into a DIV inside a template file.

You can block one or more turkers from doing this HIT by passing them as a string or array to blockWorkers.
</div>
<a name="webpageBase"><div class="func">webpageBase</div></a>
<div class="doc">
This module contains functions for creating and communicating with webpages
that will be servered from the TurKit server.
</div>
<a name="webpageBase.create"><div class="func"><span class="prefix">webpageBase.</span>create(<span class="param">contents</span>,<span class="param"> blockWorkers</span>)</div></a>
<div class="doc">
Creates a publicly accessible webpage with the given contents.
Returns the URL to the webpage.

You can block one or more turkers from doing this HIT by passing them as a string or array to blockWorkers.
</div>
<a name="webpageBase.remove"><div class="func"><span class="prefix">webpageBase.</span>remove(<span class="param">url</span>)</div></a>
<div class="doc">
Removes the webpage at the specified URL.
</div>
<a name="webpageBase.setData"><div class="func"><span class="prefix">webpageBase.</span>setData(<span class="param">url</span>,<span class="param"> data</span>)</div></a>
<div class="doc">
Webpages have a little bit of data associated with them
allowing the server and client to communicate.
This method sets that data.
</div>
<a name="webpageBase.getData"><div class="func"><span class="prefix">webpageBase.</span>getData(<span class="param">url</span>)</div></a>
<div class="doc">
Webpages have a little bit of data associated with them
allowing the server and client to communicate.
This method gets that data, if and only if it was most recently written by the client.
Returns null if the data was most recently written by the server.
</div>
<a name="print"><div class="func">print(<span class="param">s</span>)</div></a>
<div class="doc">
Prints s to the output buffer.
</div>
<a name="verbosePrint"><div class="func">verbosePrint(<span class="param">s</span>)</div></a>
<div class="doc">
Prints s if props.verbose is true.
</div>
<a name="mTurkRestRequest"><div class="func">mTurkRestRequest(<span class="param">operation</span>,<span class="param"> params</span>)</div></a>
<div class="doc">
Makes a REST request to MTurk, and returns the result as an XML object.
</div>
<a name="sleep"><div class="func">sleep(<span class="param">seconds</span>)</div></a>
<div class="doc">
Sleeps for the specified number of seconds.
</div>
<a name="md5"><div class="func">md5(<span class="param">s</span>)</div></a>
<div class="doc">
Returns the md5 hash of the given string.
</div>
<a name="json"><div class="func">json(<span class="param">o</span>)</div></a>
<div class="doc">
Returns a JSON-like representation of the JavaScript data value or object o.
You may call "eval" on the result and get back the original data structure.
This works if the structure contains nested or even circular references.
It does not handle functions.
</div>
<a name="read"><div class="func">read(<span class="param">src</span>)</div></a>
<div class="doc">
Reads the contents of the given url or file into a string.
All urls must start with "http://" or "https://"
</div>
<a name="slurp"><div class="func">slurp(<span class="param">src</span>)</div></a>
<div class="doc">
Pseudonym for <a href="#read">read</a>.
</div>
<a name="write"><div class="func">write(<span class="param">dest</span>,<span class="param"> s</span>)</div></a>
<div class="doc">
Writes to the given file.
</div>
<a name="registerMTurkNotification"><div class="func">registerMTurkNotification(<span class="param">hitId</span>)</div></a>
<div class="doc">
Tells MTurk to notify us if the given HIT changes.
This will in-turn trigger a re-run of the entire program,
and hopefully we'll get further that time,
since presumably a HIT will have been completed.
</div>
<a name="random"><div class="func">random()</div></a>
<div class="doc">
Returns a random number uniformly distributed between 0 and 1.
This function overrides the normal Math.random function as well.

<p>NOTE: The normal JavaScript Math.random uses a random seed each time the script is run.
TurKit uses the same seed between crash-and-reruns of a script,
unless you explicitly set it with <a href="#setSeed">setSeed</a>.</p>
</div>
<a name="setSeed"><div class="func">setSeed(<span class="param">seed</span>)</div></a>
<div class="doc">
Sets the random seed used by <a href="#random">random</a>.
</div>
<a name="swap"><div class="func">swap(<span class="param">o</span>,<span class="param"> i1</span>,<span class="param"> i2</span>)</div></a>
<div class="doc">
Swaps the values at the two provided indecies (<code>i1</code>, <code>i2</code>)
in the provided array <code>o</code>.

Example:
<pre>
a = [1, 2, 3]
swap(a, 0, 2)
// a is now [3, 2, 1]
</pre>
</div>
<a name="shuffle"><div class="func">shuffle(<span class="param">a</span>)</div></a>
<div class="doc">
Randomly sorts the elements of the given array.
</div>
<a name="randomIndex"><div class="func">randomIndex(<span class="param">n</span>)</div></a>
<div class="doc">
Returns an integer in the range [0, n - 1].
</div>
<a name="time"><div class="func">time()</div></a>
<div class="doc">
Returns the current time in milliseconds since the UNIX epoc.
</div>
<a name="group"><div class="func">group(<span class="param">a</span>,<span class="param"> func</span>)</div></a>
<div class="doc">
Groups the values in the object or array <code>a</code>
by the key defined for each value by running <code>func</code> on that value.
The result is a map of keys to arrays, where each array holds all the values associated with that key.	
</div>
<a name="safeJson"><div class="func">safeJson(<span class="param">s</span>)</div></a>
<div class="doc">
Returns true if it is safe to call eval on s, i.e., calling eval on s will not have any side effects aside from creating a data structure.
</div>
<a name="ensure"><div class="func">ensure(<span class="param">obj</span>,<span class="param"> path</span>,<span class="param"> defaultValue</span>)</div></a>
<div class="doc">
Ensures that a JavaScript path exists, assigns a default value to the path if it doesn't exist yet, and returns the value in either case. There are multiple ways to call this function. All of the following are equivalent:<br>
<code>
ensure("a.b[2].c", 5)<br>
ensure(null, "a.b[2].c", 5)<br>
ensure(a, "b[2].c", 5)<br>
ensure(a, ".b[2].c", 5)<br>
ensure(a, ["b", 2, "c"], 5)<br>
<br>
print(a.b[2].c)<br>
<br>
</code>
The last line prints "5". Note that the last 3 versions only work if <code>a</code> is already an object.
</div>
<a name="values"><div class="func">values(<span class="param">obj</span>)</div></a>
<div class="doc">
Returns an array of the values in an object.
@type Array
</div>
<a name="keys"><div class="func">keys(<span class="param">obj</span>)</div></a>
<div class="doc">
Returns the keys of an object as an array.
@type Array
</div>
<a name="filter"><div class="func">filter(<span class="param">a</span>,<span class="param"> test</span>)</div></a>
<div class="doc">
Filters values of an array or object using the <i>test</i> function; the original object is not affected.
The test function should accept one or two parameters.
The first parameter will be the value to process.
The second parameter will be the index of that value in the array,
or the key of that value in the object.
The function should return true or false depending on whether the value should pass the filter.
</div>
<a name="foreach"><div class="func">foreach(<span class="param">a</span>,<span class="param"> test</span>)</div></a>
<div class="doc">
Processes values of an array or object using the <i>test</i> function; the original object is not affected.
The test function should accept one or two parameters.
The first parameter will be the value to process.
The second parameter will be the index of that value in the array,
or the key of that value in the object.
If the test function returns false for a value, then the processing will stop.
</div>
<a name="map"><div class="func">map(<span class="param">a</span>,<span class="param"> test</span>)</div></a>
<div class="doc">
Maps values of an array or object using the <i>test</i> function into a new array or object with the same indicies;
the original object is not affected.
The test function should accept one or two parameters.
The first parameter will be the value to process.
The second parameter will be the index of that value in the array,
or the key of that value in the object.
The test function should return a value which will be placed
in a newly constructed array or object at the index or key of this value.
</div>
<a name="mapToSelf"><div class="func">mapToSelf(<span class="param">a</span>,<span class="param"> test</span>)</div></a>
<div class="doc">
Similar to <a href="#map">map</a>, except that it overwrites <code>a</code> with the results,
rather than returning a new object or array.
</div>
<a name="fold"><div class="func">fold(<span class="param">a</span>,<span class="param"> func</span>,<span class="param"> def</span>)</div></a>
<div class="doc">
Folds the given array or object a using func.
The func function should accept two parameters.
Each parameter will be a value from a,
or the default value def (if it is supplied),
or a return value from a previous call to func.
Every element of a will be passed to func exactly once,
in the order they appear in a.
The return value is the final value returned from func.

This function can be used to sum a list of numbers, for example.

</div>
<a name="trim"><div class="func">trim(<span class="param">s</span>)</div></a>
<div class="doc">
Removes whitespace from the front and back of the string.
</div>
<a name="last"><div class="func">last(<span class="param">a</span>)</div></a>
<div class="doc">
Returns the last element of this array.
</div>
<a name="merge"><div class="func">merge(<span class="param">objA</span>,<span class="param"> objB</span>)</div></a>
<div class="doc">
Adds the key/value pairs found in <i>objB</i> to <i>objA</i>.
For example:<br>
<code>
merge({a:1, b:2}, {c:3, d:4})
</code><br>
returns <code>{a:1, b:2, c:3, d:4}</code>
</div>
<a name="maxHelper"><div class="func">maxHelper(<span class="param">a</span>,<span class="param"> score</span>)</div></a>
<div class="doc">
Returns three values in an array:
the index or key of the max element,
the max element,
the value associated with the max element (i.e. score(maxElement)),
which is equal to the max element is no score function is provided.
</div>
<a name="max"><div class="func">max(<span class="param">a</span>,<span class="param"> score</span>)</div></a>
<div class="doc">
Returns the max element.
</div>
<a name="findMax"><div class="func">findMax(<span class="param">a</span>,<span class="param"> score</span>)</div></a>
<div class="doc">
Returns the index of the max element
</div>
<a name="escapeXml"><div class="func">escapeXml(<span class="param">s</span>)</div></a>
<div class="doc">
Escape the string for use inside XML, e.g., convert characters like &amp; into &amp;amp;.
</div>
<a name="unescapeXml"><div class="func">unescapeXml(<span class="param">s</span>)</div></a>
<div class="doc">
Unescape a string with XML escape codes, e.g., convert sequences like &amp;amp; into &amp;.
</div>
<a name="Set"><div class="func">Set(<span class="param">a</span>)</div></a>
<div class="doc">
Returns a new Set. A set is represented as an object where the values are true for keys in the set.
If <code>a</code> is a set, add it's elements to this set.
If <code>a</code> is an object, add it's values to this set.
If <code>a</code> is an element, add it to this set.
</div>
<a name="Set.prototype.clone"><div class="func"><span class="prefix">Set.prototype.</span>clone()</div></a>
<div class="doc">
Returns a clone of the Set.
</div>
<a name="Set.prototype.remove"><div class="func"><span class="prefix">Set.prototype.</span>remove(<span class="param">a</span>)</div></a>
<div class="doc">
If <code>a</code> is a set, remove it's elements from this set.
If <code>a</code> is an object, remove it's values from this set.
If <code>a</code> is an element, remove it from this set.

Returns this Set, after the removal.
If removing a single element, returns <code>true</code> iff the element existed before.
</div>
<a name="Set.prototype.add"><div class="func"><span class="prefix">Set.prototype.</span>add(<span class="param">a</span>)</div></a>
<div class="doc">
If <code>a</code> is a set, add it's elements to this set.
If <code>a</code> is an object, add it's values to this set.
If <code>a</code> is an element, add it to this set.

Returns this Set, after the addition.
If adding a single element, returns <code>true</code> iff the element didn't exist before.
</div>
<a name="Set.prototype.intersect"><div class="func"><span class="prefix">Set.prototype.</span>intersect(<span class="param">b</span>)</div></a>
<div class="doc">
Returns a new Set representing the intersection of this Set with <code>a</code>.
If <code>a</code> is an object, a set is created from its values, and the intersection is done with that.
If <code>a</code> is an element, a set is created containing this element, and the intersection is done with that.
</div>
<a name="Bag"><div class="func">Bag(<span class="param">a</span>)</div></a>
<div class="doc">
Returns a new Bag data structure,
which is an unordered collection of objects,
where objects can appear multiple times.
The bag is really a map of keys,
where the value associated with each key
represents the number of times that key appears in the bag.

If <code>a</code> is a bag, add it's elements to this bag.
If <code>a</code> is an object, add it's values to this bag.
If <code>a</code> is an element, add it to this bag.
</div>
<a name="Bag.prototype.clone"><div class="func"><span class="prefix">Bag.prototype.</span>clone()</div></a>
<div class="doc">
Returns a clone of the bag.
</div>
<a name="Bag.prototype.add"><div class="func"><span class="prefix">Bag.prototype.</span>add(<span class="param">a</span>,<span class="param"> count</span>)</div></a>
<div class="doc">
If <code>a</code> is a bag, add it's elements to this bag, and returns the new bag.
If <code>a</code> is an object, add it's values to this bag, and returns the new bag.
If <code>a</code> is an element, add it to this bag, and return the new number of times it appears.

The parameter <code>count</code> defaults to 1,
but can be changed to add multiple copies of <code>a</code> to the bag.
</div>
<a name="Bag.prototype.get"><div class="func"><span class="prefix">Bag.prototype.</span>get(<span class="param">a</span>)</div></a>
<div class="doc">
Get's the number of <code>a</code>'s in the bag.

This is different than myBag['item'],
since doing that would return null instead of 0,
if there was no 'item' in myBag.
</div>
<a name="jsonPath"><div class="func">jsonPath(<span class="param">obj</span>,<span class="param"> expr</span>,<span class="param"> arg</span>)</div></a>
<div class="doc">
see documentation here: <a href="http://goessner.net/articles/JsonPath/">http://goessner.net/articles/JsonPath/</a>

from: http://code.google.com/p/jsonpath/

JSONPath 0.8.0 - XPath for JSON

Copyright (c) 2007 Stefan Goessner (goessner.net)
Licensed under the MIT (MIT-LICENSE.txt) licence.
</div>
<a name="stats"><div class="func">stats</div></a>
<div class="doc">
Utility methods for doing statistics. More to come here in the future.
</div>
<a name="stats.sum"><div class="func"><span class="prefix">stats.</span>sum(<span class="param">a</span>)</div></a>
<div class="doc">
Calculate the sum of an array
</div>
<a name="stats.mean"><div class="func"><span class="prefix">stats.</span>mean(<span class="param">a</span>,<span class="param"> sum</span>)</div></a>
<div class="doc">
Calculate the mean of an array.
<code>sum</code> is optional -- it will be calculated if not supplied. 
</div>
<a name="stats.variance"><div class="func"><span class="prefix">stats.</span>variance(<span class="param">a</span>,<span class="param"> mean</span>)</div></a>
<div class="doc">
Calculate the variance of an array.
<code>mean</code> is optional -- it will be calculated if not supplied. 
</div>
<a name="stats.sd"><div class="func"><span class="prefix">stats.</span>sd(<span class="param">a</span>,<span class="param"> mean</span>)</div></a>
<div class="doc">
Calculate the standard deviation of an array.
<code>mean</code> is optional -- it will be calculated if not supplied. 
</div>
<a name="stats.all"><div class="func"><span class="prefix">stats.</span>all(<span class="param">a</span>)</div></a>
<div class="doc">
Calculate the sum, mean, variance and standard deviation of <code>a</code>.
</div>
<a name="highlightDiff"><div class="func">highlightDiff(<span class="param">a</span>,<span class="param"> b</span>)</div></a>
<div class="doc">
<p>Takes two strings <code>a</code> and <code>b</code>, and calculates their differences.
The differences are highlighted in each result using HTML span tags with yellow backgrounds.
There are two resulting strings of HTML, returned in an object with two properties, <code>a</code> and <code>b</code>.</p>
</div>


</div>

</div>

</body>
</html>
